package org.gingresosapi.persistencia;

import org.gingresosapi.beans.Comercios;
import java.sql.Date; 
import org.gingresosapi.beans.*;
import org.gingresosapi.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.gingresosapi.generales.Mensajeria;
import org.gingresosapi.generales.DataGManager;


/**
*
* @author
*/

public class ComerciosPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/gingresosapi/properties/mensajes");
static DataGManager dataGManager;
static List<Comercios> list;

public ComerciosPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Comercios comercios ) {
  excepcion = null;
  try {
      esMensaje =false;
   
   
   

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into comercios(idcomercio,cedula,comercio,ruc,descripcion,direccion,idcorregimiento,telefono,fecha,hipotecado,bajado,traspaso,secuestrado,idmunicipio,estatal,activo,idusuario)  values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setString(1,comercios.getIdcomercio());
        pinsert.setString(2,comercios.getCedula());
        pinsert.setString(3,comercios.getComercio());
        pinsert.setString(4,comercios.getRuc());
        pinsert.setString(5,comercios.getDescripcion());
        pinsert.setString(6,comercios.getDireccion());
        pinsert.setString(7,comercios.getIdcorregimiento());
        pinsert.setString(8,comercios.getTelefono());
        pinsert.setDate(9,comercios.getFecha());
        pinsert.setString(10,comercios.getHipotecado());
        pinsert.setString(11,comercios.getBajado());
        pinsert.setString(12,comercios.getTraspaso());
        pinsert.setString(13,comercios.getSecuestrado());
        pinsert.setString(14,comercios.getIdmunicipio());
        pinsert.setString(15,comercios.getEstatal());
        pinsert.setString(16,comercios.getActivo());
        pinsert.setString(17,comercios.getIdusuario());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Comercios comercios ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update comercios set  idcomercio=?, cedula=?, comercio=?, ruc=?, descripcion=?, direccion=?, idcorregimiento=?, telefono=?, fecha=?, hipotecado=?, bajado=?, traspaso=?, secuestrado=?, idmunicipio=?, estatal=?, activo=?, idusuario=?  where  idcomercio ='"+comercios.getIdcomercio()+"' and  idmunicipio ='"+comercios.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setString(1,comercios.getIdcomercio());
pupdate.setString(2,comercios.getCedula());
pupdate.setString(3,comercios.getComercio());
pupdate.setString(4,comercios.getRuc());
pupdate.setString(5,comercios.getDescripcion());
pupdate.setString(6,comercios.getDireccion());
pupdate.setString(7,comercios.getIdcorregimiento());
pupdate.setString(8,comercios.getTelefono());
pupdate.setDate(9,comercios.getFecha());
pupdate.setString(10,comercios.getHipotecado());
pupdate.setString(11,comercios.getBajado());
pupdate.setString(12,comercios.getTraspaso());
pupdate.setString(13,comercios.getSecuestrado());
pupdate.setString(14,comercios.getIdmunicipio());
pupdate.setString(15,comercios.getEstatal());
pupdate.setString(16,comercios.getActivo());
pupdate.setString(17,comercios.getIdusuario());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  comercios set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Comercios comercios_old , Comercios comercios) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update comercios set  idcomercio=? ,  idmunicipio=?  where  idcomercio ='"+comercios_old.getIdcomercio()+"' and  idmunicipio ='"+comercios_old.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setString(1,comercios.getIdcomercio());pupdate.setString(14,comercios.getIdmunicipio());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Comercios comercios ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from comercios  where  idcomercio = ? and  idmunicipio = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setString(1,comercios.getIdcomercio());
pdelete.setString(14,comercios.getIdmunicipio());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from comercios where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from comercios  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Comercios comercios) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from comercios where idcomercio='"+comercios.getIdcomercio()+"' and idmunicipio='"+comercios.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Comercios findByPrimaryKey(Comercios comercios) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from comercios where idcomercio='"+comercios.getIdcomercio()+"' and idmunicipio='"+comercios.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
            
            
            comercios.setIdcomercio(rs.getString("idcomercio"));
comercios.setCedula(rs.getString("cedula"));
comercios.setComercio(rs.getString("comercio"));
comercios.setRuc(rs.getString("ruc"));
comercios.setDescripcion(rs.getString("descripcion"));
comercios.setDireccion(rs.getString("direccion"));
comercios.setIdcorregimiento(rs.getString("idcorregimiento"));
comercios.setTelefono(rs.getString("telefono"));
comercios.setFecha(rs.getDate("fecha"));
comercios.setHipotecado(rs.getString("hipotecado"));
comercios.setBajado(rs.getString("bajado"));
comercios.setTraspaso(rs.getString("traspaso"));
comercios.setSecuestrado(rs.getString("secuestrado"));
comercios.setIdmunicipio(rs.getString("idmunicipio"));
comercios.setEstatal(rs.getString("estatal"));
comercios.setActivo(rs.getString("activo"));
comercios.setIdusuario(rs.getString("idusuario"));
    }
    rs.close();
    psquery.close();
 return comercios;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdcomercio()
*/

public static List<Comercios> findByIdcomercio(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where idcomercio='"+comercios.getIdcomercio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByCedula()
*/

public static List<Comercios> findByCedula(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where cedula='"+comercios.getCedula()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByComercio()
*/

public static List<Comercios> findByComercio(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where comercio='"+comercios.getComercio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByRuc()
*/

public static List<Comercios> findByRuc(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where ruc='"+comercios.getRuc()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByDescripcion()
*/

public static List<Comercios> findByDescripcion(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where descripcion='"+comercios.getDescripcion()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByDireccion()
*/

public static List<Comercios> findByDireccion(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where direccion='"+comercios.getDireccion()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdcorregimiento()
*/

public static List<Comercios> findByIdcorregimiento(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where idcorregimiento='"+comercios.getIdcorregimiento()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTelefono()
*/

public static List<Comercios> findByTelefono(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where telefono='"+comercios.getTelefono()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFecha()
*/

public static List<Comercios> findByFecha(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where fecha='"+comercios.getFecha()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByHipotecado()
*/

public static List<Comercios> findByHipotecado(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where hipotecado='"+comercios.getHipotecado()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByBajado()
*/

public static List<Comercios> findByBajado(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where bajado='"+comercios.getBajado()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTraspaso()
*/

public static List<Comercios> findByTraspaso(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where traspaso='"+comercios.getTraspaso()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findBySecuestrado()
*/

public static List<Comercios> findBySecuestrado(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where secuestrado='"+comercios.getSecuestrado()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdmunicipio()
*/

public static List<Comercios> findByIdmunicipio(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where idmunicipio='"+comercios.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByEstatal()
*/

public static List<Comercios> findByEstatal(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where estatal='"+comercios.getEstatal()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByActivo()
*/

public static List<Comercios> findByActivo(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where activo='"+comercios.getActivo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdusuario()
*/

public static List<Comercios> findByIdusuario(Comercios comercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
      String sql = "select * from comercios where idusuario='"+comercios.getIdusuario()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Comercios> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Comercios>();
  String sql = "select * from comercios";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from comercios";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from comercios where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from comercios";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from comercios where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Comercios> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Comercios>();
  String sql = "select * from comercios where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Comercios> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Comercios>();
  String sql = "select * from comercios";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "comercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
        Comercios comercios2 = new Comercios(
         rs.getString("idcomercio"),rs.getString("cedula"),rs.getString("comercio"),rs.getString("ruc"),rs.getString("descripcion"),rs.getString("direccion"),rs.getString("idcorregimiento"),rs.getString("telefono"),rs.getDate("fecha"),rs.getString("hipotecado"),rs.getString("bajado"),rs.getString("traspaso"),rs.getString("secuestrado"),rs.getString("idmunicipio"),rs.getString("estatal"),rs.getString("activo"),rs.getString("idusuario"));
            
            
       list.add(comercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
